<?php 
	include '../init.php';
	include ADMIN_PATH.'/header.php';

	$model=new Model('user');
	//每页显示2条
	$num=2;
	//查询总条数
	$sql="select count(`id`) from `user`";
	$list1=$model->find($sql);
	//var_dump($list1);
	//总条数
	$total=$list1[0]['count(`id`)'];
	//var_dump($total);
	//总页数
	$pages=ceil($total/$num);

	//当前页
	$p=$_GET['p']?$_GET['p']:1;
	
	if ($p>$pages) 
	{
		$p=$pages;
	}
	if ($p<1) 
	{
		$p=1;
	}
	//开始的
	$start=($p-1)*$num;
	//偏移量(一次出现几条)
	$offset=$num;
	//下一页
	$next=$p+1;
	//上一页
	$prev=$p-1;

	$limit=$start.','.$offset;
	$where='';
	$list=$model->select($where,$limit);
	$str="
	<a href='".ADMIN_URL."/user/index.php'>首页</a>
	<a href='".ADMIN_URL."/user/index.php?p=$prev'>上一页</a>
	<a href='".ADMIN_URL."/user/index.php?p=$prev'>$prev</a>
	<a href='".ADMIN_URL."/user/index.php?p=$p'>$p</a>
	<a href='".ADMIN_URL."/user/index.php?p=$next'>$next</a>
	<a href='".ADMIN_URL."/user/index.php?p=$next'>下一页</a>
	<a href='".ADMIN_URL."/user/index.php?p=$pages'>尾页</a>
	";


?>
<div class="m_right">
	<div class="m_main">
		<h1 style="font:bold 26px/40px 宋体;">这是用户管理页面</h1>
		<table class="table" border="1" cellspacing="0" cellpadding="5" >
			
			<tr bgcolor="#ccc" height="50">
				<th>编号</th>
				<th>用户名</th>
				<th>状态</th>
				<th>时间</th>
				<th>操作</th>
			</tr>
				<?php foreach ($list as $key => $value) :?>
				<tr>
					<td><?php echo $value['id'];?></td>
					<td><?php echo $value['username'];?></td>
					<td>
						<?php 
							echo $value['status']?'<a href="'.ADMIN_URL.'/user/action.php?a=up&p='.$p.'&id='.$value['id'].'"><img style="display:block;border-radius:40px;margin:0 auto;" src="'.URL.'/public/images/dui.png"></a>':'<a href="'.ADMIN_URL.'/user/action.php?a=up&p='.$p.'&id='.$value['id'].'"><img style="display:block;border-radius:40px;margin:0 auto;"src="'.URL.'/public/images/x.png"></a>';
								?>
					</td>
					<td><?php echo date('Y年m月d日',$value['regtime']);?></td>
					<td>
						<a href="<?php echo ADMIN_URL;?>/user/detail.php?id=<?php echo $value['id'];?>">查看详情</a>|<a href="<?php echo ADMIN_URL;?>/user/edit.php?id=<?php echo $value['id'];?>">修改</a>|
						<a href="<?php echo ADMIN_URL;?>/user/action.php?a=del&id=<?php echo $value['id'];?>">删除</a>
					</td>
			</tr>
					


					<?php endforeach;?>
					
					<tr>
						<th colspan="5" height="50">
							<?php echo $str;?>
						</th>
					</tr>
				</table>
	</div>
	
</div>
<?php 
	include ADMIN_PATH.'/footer.html';
?>